package com.molichuxing.gateway.api.services.impl;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.molichuxing.framework.exception.BizException;
import com.molichuxing.framework.result.ResponseResult;
import com.molichuxing.gateway.api.services.UserApiService;
import com.molichuxing.gateway.bff.user.entity.response.UserVo;
import com.molichuxing.gateway.bff.user.services.UserBffService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author liyg
 * 用户web接口实现类
 * 2019-08-26
 *
 */
@Api(tags = "用户相关接口")
@RestController
@RequestMapping(value = "/user")
public class UserApiServiceImpl extends RootApiService implements UserApiService {

	private static final Logger logger = LoggerFactory.getLogger(UserApiServiceImpl.class);

	@Resource
	private UserBffService userBffService;
	
	/**
	 *根据订单编号获取用户信息 
	 * @param
	 * @return
	 */
	@Override
	@ApiOperation(value = "根据订单编号获取用户信息 ")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderCode", value = "订单编号", required = true, dataType = "Long")
	})
	@GetMapping(value = "/user/order/detail")
	public ResponseResult<UserVo> getUserByOrderCode(@RequestParam Long orderCode) {
		
		ResponseResult<UserVo> result = new ResponseResult<>();
		try {
			return result.success(userBffService.getUserByOrderCode(orderCode));
		}catch (BizException e) {
			logger.error("[getUserByOrderCode]根据订单编号获取用户信息异常", e.getMessage());
			result.error(e.getMessage());
		}catch (Exception e) {
			logger.error("[getUserByOrderCode]根据订单编号获取用户信息异常", e);
			result.error("根据订单编号获取用户信息异常");
		}
		return result;
	}
	
}
